package com.xty.xtyle.db;

import android.text.TextUtils;

import com.xty.xtyle.db.cloth.Cloth;

import org.litepal.LitePal;

import java.util.List;

public class ClothTypesDao {

    public void add(ClothTypes cloth) {
        String type = cloth.getType();
        ClothTypes types = findClothType(type);
        if (null == types) {
            ClothTypes clothTypes = new ClothTypes(type);
            clothTypes.save();
        }
    }

    public void update(ClothTypes cloth, String type) {
        if (null == cloth || TextUtils.isEmpty(type)) return;
        cloth.updateAll("type = ?",type);
    }

    public void delete(String type) {
        if (TextUtils.isEmpty(type)) return;
        LitePal.deleteAll(ClothTypesDao.class, "type=?", type);
    }

    public List<ClothTypes> findAll() {
        return LitePal.findAll(ClothTypes.class);
    }

    public ClothTypes findClothType(String type) {
        if (TextUtils.isEmpty(type)) return null;
        return LitePal.where("type=?", type).findFirst(ClothTypes.class);
    }

    public List<ClothTypes> findAllByTypes(String type) {
        return LitePal.where("type=?", type).find(ClothTypes.class);
    }

    public void order() {
//        List<cloth> books = LitePal.order("price desc").find(Book.class);
    }
}
